package net.wanho.R;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * 这个类是：
 *
 * @author: MENG HU WANG
 * @date: 2025/1/12 15:53
 * @version: 1.0
 */


@Data
@NoArgsConstructor
@AllArgsConstructor
public class R {
    private Integer code;
    private Boolean success;
    private String message;
    private Object data;


    public static R ok(Object data) {
        return new R(HttpStatus.OK.value(), true, "操作成功", data);
    }

    public static R ok(String message) {
        return new R(HttpStatus.OK.value(), true, message, null);
    }

    public static R ok() {
        return new R(HttpStatus.OK.value(), true, "操作成功", null);
    }

    public static R ok(String message, Object data) {
        return new R(HttpStatus.OK.value(), true, message, data);
    }

    public static R error(String message) {
        return new R(HttpStatus.INTERNAL_SERVER_ERROR.value(), false, message, null);
    }

    public static R error(Integer code, String message) {
        return new R(code, false, message, null);
    }

    public static R error(Object data) {
        return new R(HttpStatus.INTERNAL_SERVER_ERROR.value(), false, "操作失败", data);
    }

}
